/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __FUNCEVALUATOR_H__
#define __FUNCEVALUATOR_H__

#include "EvolutiveLib.h"
#include "Evaluator.h"

namespace Evolutive {

	//! Predefined functions
	enum EVOLUTIVELIB_API PREDEF_FUNCTION {PREDFUNC_NONE,PREDFUNC_4_PEAKS,PREDFUNC_SUM,PREDFUNC_HIFF,PREDFUNC_ISOPEAK,PREDFUNC_ISOTORUS,
									PREDEF_SPHERE,PREDEF_RASTRIGIN,PREDEF_ROSENBROCK,PREDEF_GRIEWANGK,PREDEF_ACKLEYS,
									PREDFUNC_ONEMAX,PREDFUNC_PLATEAU,PREDFUNC_CHECKERBOARD,PREDFUNC_EQPRODUCTS,PREDFUNC_6_PEAKS};

	class EVOLUTIVELIB_API CFuncEvaluator : public CEvaluator
	{
		//! Methods
	public:
		//! Default constructor		
		CFuncEvaluator(void);

		//! Default destructor
		virtual ~CFuncEvaluator(void);

		//! Set function
		void SetFunction(PREDEF_FUNCTION Function,int NumVars);

		//! Returns the score for a given chromosome (from base class)
		virtual double GetScore(CChromosome *C);	

		//! Verify if a certain Chromosome is a valid solution (from base class)
		virtual bool IsValid(CChromosome *C);

		//! Sets extra parameters for the function
		void SetFncParameters(double *Parameters);

		//! Returns the optimum value for given parameters and function
		double GetOptimumValue(void);

		//! Instantiate an string with the problem name
		char* GetProblemName(char *Buffer);
				
	private:
		//! Evaluate the 4-Peaks problem over the given data
		double Fnc4Peaks(int NumFields,unsigned int *Values);

		//! Evaluate the Sum problem over the given data
		double FncSum(int NumFields,unsigned int *Values);

		//! Evaluate the HIFF problem over the given data
		double FncHIFF(int NumFields,unsigned int *Values);

		//! Evaluate the IsoPeak problem over the given data
		double FncIsoPeak(int NumFields,unsigned int *Values);

		//! Evaluate the IsoTorus problem over the given data
		double FncIsoTorus(int NumFields,unsigned int *Values);

		//! Evaluate the Sphere function over the given point
		double FncSphere(int NumFields,double *Values);

		//! Evaluate the Rastrigin function over the given point
		double FncRastrigin(int NumFields,double *Values);

		//! Evaluate the Rosenbrock function over the given point
		double FncRosenbrock(int NumFields,double *Values);

		//! Evaluate the Griewangk function over the given point
		double FncGriewangk(int NumFields,double *Values);

		//! Evaluate the Ackleys function over the given point
		double FncAckleys(int NumFields,double *Values);

		//! Evaluate the OneMax problem over the given data
		double FncOneMax(int NumFields,unsigned int *Values);

		//! Evaluate the Plateau problem over the given data
		double FncPlateau(int NumFields,unsigned int *Values);

		//! Evaluate the Checkerboard problem over the given data
		double FncCheckerboard(int NumFields,unsigned int *Values);

		//! Evaluate the Equal Products problem over the given data
		double FncEqProducts(int NumFields,unsigned int *Values);

		//! Evaluate the 6-Peaks problem over the given data
		double Fnc6Peaks(int NumFields,unsigned int *Values);

						
		//! Attributes
	private:		

		//! Selected function
		PREDEF_FUNCTION m_SelectedFunc;

		//! Pointer to the parameters of the function
		double *m_Parameters;
	};	
}

#endif // __FUNCEVALUATOR_H__
